#ifndef _SPINOR_INTERFACE_H
#define _SPINOR_INTERFACE_H

#include "spi_drv.h"

/********** Define **********/
#define NORSPI_INSTANCE SPI3
#define SPIFLASH_SPI_CS_PORT EPORT1
#define SPIFLASH_SPI_CS_PIN EPORT_PIN8

#define SPIFLASH_SECTOR_SIZE 4096
#define SPIFLASH_PAGE_SIZE 256
#define SPIFLASH_REG_WRITE_DATA 0x02
#define SPIFLASH_REG_READ_DATA 0x03
#define SPIFLASH_REG_READ_ID 0x90
#define SPIFLASH_REG_ERASE_SECTOR 0x20
#define SPIFLASH_REG_WRITE_EN 0x06
#define SPIFLASH_REG_READ_STA_REG 0x05

#define SPI_TIMEOUT 0
#define SPIFLASH_SPI_CS_HIGH DRV_EPORT_WritePinsLevel(SPIFLASH_SPI_CS_PORT, SPIFLASH_SPI_CS_PIN, GPIO_HIGH)
#define SPIFLASH_SPI_CS_LOW DRV_EPORT_WritePinsLevel(SPIFLASH_SPI_CS_PORT, SPIFLASH_SPI_CS_PIN, GPIO_LOW);

#define SPINORLOG_DEBUG(...) printf(__VA_ARGS__)
void SPIFLASH_Init(void);
uint16_t SPIFLASH_ReadID(void);
void SPIFLASH_Write(uint32_t addr, uint8_t *pWBuf, uint16_t pWBufLen);
void SPIFLASH_Read(uint32_t addr, uint8_t *pRBuf, uint32_t pRBufLen);
#endif
